const JWT = require('../utils/jwt');

const auth = (req, res, next) => {
  const tokenInfo = JWT.getTokenInfo(req.header('Authorization'));

  if (!tokenInfo) {
    return res.status(401).json({
      success: false,
      message: '请先登录'
    });
  }

  // 将用户信息附加到请求对象
  req.user = tokenInfo;
  next();
};

module.exports = auth; 